/*
 * @Descripttion:
 * @version:
 * @Author: huanglp
 * @Date: 2022-11-24 13:52:56
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-11-24 17:54:55
 */
import { SysDictTypeApi } from '/@/api/system/basedata/SysDictTypeApi';
import { onBeforeMount, reactive } from 'vue';

export default function (dictList) {
  const initValue = {};
  for (let index = 0; index < dictList.length; index++) {
    const element = dictList[index];
    initValue[element + 'List'] = [];
    initValue[element + 'Obj'] = {};
  }
  const dictListData = reactive({ ...initValue });
  onBeforeMount(async () => {
    for (let index = 0; index < dictList.length; index++) {
      const element = dictList[index];
      const result = await SysDictTypeApi.getDictListByParams({ dictTypeCode: element });
      dictListData[element + 'List'] = result;
      const obj = {};
      result.forEach((item) => {
        obj[item.dictCode] = item.dictName;
      });
      dictListData[element + 'Obj'] = obj;
    }
  });

  return {
    dictListData,
  };
}

// import getDictListData from '@/utils/dictListData'
// const {dictListData} = getDictListData(['fender','panelName']);
// console.log(`output->dictListData`,dictListData)
/// log ============================

//   {
//   "fenderList": [

//   ],
//   "fenderObj": {

//   },
//   "panelNameList": [

//   ],
//   "panelNameObj": {

//   }
// }
